package constant.milk.cashbook.select;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import constant.milk.cashbook.R;
import constant.milk.cashbook.SuperActivity;

public class SelectTypeActivity extends SuperActivity
{
	public static final String TYPE_DATA = "TYPE_DATA";

	private View allView;
	private View outView;
	private View inView;
	private View moveView;
	private View creditView;
	private View phoneView;
	private View fanInView;
	private View fanOutView;
	private View giftCardOutView;
	private View giftCardInView;
	
	private RadioButton allRadioButton;
	private RadioButton outRadioButton;
	private RadioButton inRadioButton;
	private RadioButton moveRadioButton;
	private RadioButton creditRadioButton;
	private RadioButton phoneRadioButton;
	private RadioButton fanInRadioButton;
	private RadioButton fanOutRadioButton;
	private RadioButton giftCardOutRadioButton;
	private RadioButton giftCardInRadioButton;
	
	private Button checkButton;
	
	private String typeStr;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.select_type_activity);
		
		setTitle("타입선택");
		
		setGoneTipButton();
		
		setFindViewId();
		setOnClick();
		setData();
	}

	@Override
	protected void setFindViewId()
	{
		allView = findViewById(R.id.selectTypeAllView);
		outView = findViewById(R.id.selectTypeOutView);
		inView = findViewById(R.id.selectTypeInView);
		moveView = findViewById(R.id.selectTypeMoveView);
		creditView = findViewById(R.id.selectTypeCreditCardView);
		phoneView = findViewById(R.id.selectTypePhoneView);
		fanInView = findViewById(R.id.selectTypeFanInView);
		fanOutView = findViewById(R.id.selectTypeFanOutView);
		giftCardOutView = findViewById(R.id.selectTypeGiftCardOutView);
		giftCardInView = findViewById(R.id.selectTypeGiftCardInView);
		
		allRadioButton = (RadioButton) findViewById(R.id.selectTypeAllRadio);
		outRadioButton = (RadioButton) findViewById(R.id.selectTypeOutRadio);
		inRadioButton = (RadioButton) findViewById(R.id.selectTypeInRadio);
		moveRadioButton = (RadioButton) findViewById(R.id.selectTypeMoveRadio);
		creditRadioButton = (RadioButton) findViewById(R.id.selectTypeCreditCardRadio);
		phoneRadioButton = (RadioButton) findViewById(R.id.selectTypePhoneRadio);
		fanInRadioButton = (RadioButton) findViewById(R.id.selectTypeFanInRadio);
		fanOutRadioButton = (RadioButton) findViewById(R.id.selectTypeFanOutRadio);
		giftCardOutRadioButton = (RadioButton) findViewById(R.id.selectTypeGiftCardOutRadio);
		giftCardInRadioButton = (RadioButton) findViewById(R.id.selectTypeGiftCardInRadio);
		
		checkButton = (Button) findViewById(R.id.checkButton);
	}

	@Override
	protected void setOnClick()
	{
		allView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setRadioButton(0);
			}
		});
		
		outView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setRadioButton(1);
			}
		});
		
		inView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setRadioButton(2);
			}
		});
		
		moveView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setRadioButton(3);
			}
		});
		
		creditView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setRadioButton(4);
			}
		});
		
		phoneView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setRadioButton(5);
			}
		});
		
		fanInView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setRadioButton(6);
			}
		});
		
		fanOutView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setRadioButton(7);
			}
		});
		
		giftCardOutView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setRadioButton(8);
			}
		});
		
		giftCardInView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setRadioButton(9);
			}
		});
		
		checkButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent();
				intent.putExtra(TYPE_DATA, typeStr);
				setResult(Activity.RESULT_OK, intent);
				finish();
			}
		});
		
	}

	@Override
	protected void setData()
	{
		Intent intent = getIntent();
		String data = intent.getStringExtra(TYPE_DATA);
		
		if (data.equals(getString(R.string.all)))
		{
			setRadioButton(0);
		}
		else if (data.equals(getString(R.string.out)))
		{
			setRadioButton(1);
		}
		else if (data.equals(getString(R.string.in)))
		{
			setRadioButton(2);
		}
		else if (data.equals(getString(R.string.move)))
		{
			setRadioButton(3);
		}
		else if (data.equals(getString(R.string.creditCardAsset)))
		{
			setRadioButton(4);
		}
		else if (data.equals(getString(R.string.phoneAsset)))
		{
			setRadioButton(5);
		}
		else if (data.equals(getString(R.string.fanIn)))
		{
			setRadioButton(6);
		}
		else if (data.equals(getString(R.string.fanOut)))
		{
			setRadioButton(7);
		}
		else if (data.equals(getString(R.string.giftCardOut)))
		{
			setRadioButton(8);
		}
		else if (data.equals(getString(R.string.giftCardIn)))
		{
			setRadioButton(9);
		}
	}
	
	private void setRadioButton(int flag)
	{
		allRadioButton.setChecked(false);
		outRadioButton.setChecked(false);
		inRadioButton.setChecked(false);
		moveRadioButton.setChecked(false);
		creditRadioButton.setChecked(false);
		phoneRadioButton.setChecked(false);
		fanInRadioButton.setChecked(false);
		fanOutRadioButton.setChecked(false);
		giftCardOutRadioButton.setChecked(false);
		giftCardInRadioButton.setChecked(false);
		
		if (flag == 0)
		{
			allRadioButton.setChecked(true);
			typeStr = getString(R.string.all);
		}
		else if (flag == 1)
		{
			outRadioButton.setChecked(true);
			typeStr = getString(R.string.out);
		}
		else if (flag == 2)
		{
			inRadioButton.setChecked(true);
			typeStr = getString(R.string.in);
		}
		else if (flag == 3)
		{
			moveRadioButton.setChecked(true);
			typeStr = getString(R.string.move);
		}
		else if (flag == 4)
		{
			creditRadioButton.setChecked(true);
			typeStr = getString(R.string.creditCardAsset);
		}
		else if (flag == 5)
		{
			phoneRadioButton.setChecked(true);
			typeStr = getString(R.string.phoneAsset);
		}
		else if (flag == 6)
		{
			fanInRadioButton.setChecked(true);
			typeStr = getString(R.string.fanIn);
		}
		else if (flag == 7)
		{
			fanOutRadioButton.setChecked(true);
			typeStr = getString(R.string.fanOut);
		}
		else if (flag == 8)
		{
			giftCardOutRadioButton.setChecked(true);
			typeStr = getString(R.string.giftCardOut);
		}
		else if (flag == 9)
		{
			giftCardInRadioButton.setChecked(true);
			typeStr = getString(R.string.giftCardIn);
		}
	}
	
	@Override
	protected void tipButton()
	{
	}
}
